#!/usr/bin/python3
# -*- coding: utf-8 -*-

from playwright.sync_api import Page


class Keyboard:
    def __init__(self, page: Page):
        self.page = page
        self.keyboard = self.page.keyboard

    def down(self, key):
        """向下按键,例如：Control+"""
        self.keyboard.down(key)

    def up(self):
        """释放按键"""
        self.keyboard.up()

    def insert_text(self, text):
        """插入文本"""
        self.keyboard.insert_text(text)

    def press(self, key=None):
        """按住"""
        self.keyboard.press(key)

    def type(self, text, delay=0):
        """为文本中的每个字符发送keydown、keypress/input和事件"""
        self.keyboard.type(text, delay=delay)
